#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int w=1,s=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w*=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        s=(s<<1)+(s<<3)+ch-'0';
        ch=getchar();
    }
    return w*s;
}
int T;
map<int ,int >ma;
map<int ,int>::iterator it;

int main(){
freopen("color.in","r",stdin);
freopen("color.out","w",stdout);
T=read();
for(int l=1;l<=T;l++){
    unsigned long long s=0;
    map<int ,int >ma;
    int n=read();
    if(n<=15){
        for(int i=0;i<=65535;i++){

        }
    }
    for(int i=1;i<=n;i++){
        int x=read();
        ma[x]++;
    }
    for(it=ma.begin();it!=ma.end();it++){
        //cout<<it->second/2<<" "<<it->first<<endl;
        s+=(((it->second)-1)*it->first);
    }
    //cout<<endl;
    cout<<s<<endl;
}


return 0;
}
/*
15
     13       12  13
2 3 3 4 5 5 5 5 6 7 8 11 12 13 13


15
5 3 7 2 4 13 11 6 5 5 3 5 12 8 13
2           1  1  2 2      2           1
*/
